package com.example.hibernate.program;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "DEPARTMENTS", schema = "HB")
public class Department implements Serializable {

	private long id;
	private String name;
	private Set<Employee> employees;

	public Department() {
		this.employees = new HashSet<Employee>();
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "DEPARTMENT_ID")
	@Access(AccessType.FIELD)
	public long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	@Column(name = "DEPARTMENT_NAME", nullable = false, length = 50)
	public void setName(String name) {
		this.name = name;
	}

	@OneToMany(mappedBy="department")
	public Set<Employee> getEmployees() {
		return employees;
	}

	public void setEmployees(Set<Employee> employees) {
		this.employees = employees;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) return true;
		if (obj == null) return false;
		if (getClass() != obj.getClass()) return false;
		Department other = (Department) obj;
		if (id != other.id) return false;
		return true;
	}

	@Override
	public String toString() {
		return "Deparment [id=" + id + ", name=" + name + "]";
	}

}
